package com.wx.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.wx.pojo.Commodity;
import com.wx.pojo.vo.JsonResult;
import com.wx.service.FileService;

@RestController
@RequestMapping("/pic/")
public class FileController {

	@Autowired
	FileService fileService;
	
	/*
	 * 上传图片   并且创建一个商品
	 */
	@RequestMapping("upload")
	public JsonResult uploadFile(MultipartFile uploadFile,String token) {
		return new JsonResult(fileService.uploadFile(uploadFile, token));
	}
	
	/**
	 * 根据商品id查询商品详情信息
	 */
	@RequestMapping("findComm")
	public JsonResult findCommodityById(String token,Integer id) {
		return new JsonResult(fileService.findCommodityById(token,id));
	}
	
	/**
	 * 修改商品
	 * @param token
	 * @param commodity
	 * @return
	 */
	@RequestMapping("update")
	public JsonResult updateImg(String token,Commodity commodity) {
		fileService.updateImg(token,commodity);
		return new JsonResult("update ok");
	}
	
	/*
	 * 查询该用户创建的商品    返回一个对象数组
	 */
	@RequestMapping("findComms")
	public JsonResult findImgs(String token) {
		return new JsonResult(fileService.findImgsByUserId(token));
	}
	
}
